package com.holi.hiteacher.activity;

import android.content.Context;
import android.content.Intent;
import android.databinding.DataBindingUtil;
import android.os.Bundle;
import android.support.v7.widget.Toolbar;
import android.view.View;

import com.holi.hiteacher.R;
import com.holi.hiteacher.bean.EmailBean;
import com.holi.hiteacher.data.DatabaseUtil;
import com.holi.hiteacher.databinding.AtyEmailBinding;

import butterknife.BindView;
import butterknife.ButterKnife;

public class EmailAty extends BaseActivity {
    private static String EMAIL_ID = "id";

    public static void start(Context context, int id) {
        Intent intent = new Intent(context, EmailAty.class);
        intent.putExtra(EMAIL_ID, id);
        context.startActivity(intent);
    }

    @BindView(R.id.toolbar)
    Toolbar mToolbar;

    private AtyEmailBinding binding;
    private EmailBean mData;
    private int mId;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        binding = DataBindingUtil.setContentView(this, R.layout.aty_email);
        ButterKnife.bind(this);
        initToolbar();

        getIntentData();

        mData = DatabaseUtil.getEmailBean(mId);
        mData.setReaded(true);
        //将数据库中数据更新为已读
        DatabaseUtil.updateEmailBean(mData);

        binding.setData(mData);
    }

    private void getIntentData() {
        mId = getIntent().getIntExtra(EMAIL_ID, -1);
        if (mId == -1)
            throw new IllegalArgumentException("Intent data(id): " + mId + " not illegal.");
    }

    private void initToolbar() {
        mToolbar.setTitle("我的消息");
        setSupportActionBar(mToolbar);
        mToolbar.setNavigationIcon(R.drawable.ic_keyboard_arrow_left_white);
        mToolbar.setNavigationOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                finish();
            }
        });
    }
}
